﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExaminationSys.DataAccess;
using ExaminationSys.DataAccess.Entity;
using Ext.Net;
using ExaminationSys.DataAccess.Repository;
using System.Xml.Linq;
using ExaminationSys.Helper;

namespace ExaminationSys.View.Section
{
    public partial class SectionDetailList : System.Web.UI.Page
    {

        private static readonly SectionInfoService Proxy = ObjectFactory<SectionInfoService>.Create();
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!X.IsAjaxRequest)
            //{
            //    SectionInfoDetail_RefreshData();
            //}

            if (!X.IsAjaxRequest)
            {
                SectionInfoDetail_RefreshData();
            }
        }

        private int pageSize = 20;
        public static PageEntity PageEntity = null;
        protected void SectionInfoDetail_RefreshData()
        {
            var teacherid = FormsAuthenticationHelper.GetCurrentTeacherInfo().ID;
            string sqlWhere = " 1=1   and  status<>0 ";
            sqlWhere += string.Format(" and  ID in (select  SectionID from  TeacherPrivilegeRel where TeacherID='{0}') ", teacherid);
            int pageIndex = 0;
    
            int totalPage, totalRecord;
            var items= Proxy.GetListByPage(sqlWhere, " OrderIndex asc,OperatorTime desc", pageSize, pageIndex, out totalPage, out totalRecord);
            var query = from i in items 
                        select new {
                            Title = i.Name,
                            Icon = "../../resources/images/icon.png",
                            SectionID=i.ID,
                            Items = ( from t in SectionTypeItem.GetSectionTypeItem() select t).Where(a => a.SectionTypeId==i.SectionTypeID)
            };


            this.Store1.DataSource = query;
            this.Store1.DataBind();

        }

        [DirectMethod]
        protected void ItemClickH(object sender, DirectEventArgs e)
        {
            var a = "aa";
        }


        [DirectMethod]
        public string update(string a)
        {
            return "hi," + a ;
        }

      
    }
}